package com.t235.gc.biz.controller;

import com.t235.gc.AjaxResult;
import com.t235.gc.dao.UsersDao;
import com.t235.gc.entity.Users;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.security.Principal;

@RestController
@CrossOrigin
@Api(tags = "演示模块的控制器，提供简单的swagge文档用法例子")
public class DemoController {
    @Resource
    private UsersDao usersDao;
    @Value("${server.port}")
    private String port;

    @RequestMapping("/me")
    public Principal me(Principal principal, HttpSession session) {
        return principal;
    }

    @PostMapping("/post")
    public AjaxResult post(String name, String password) {
        return AjaxResult.success("post submit success:" + name + "," + password);
    }
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Users users) {
        return AjaxResult.success("RequestBody post  submit success:" + users);
    }
    @ApiOperation(value = "演示方法1", notes = "演示方法，可以测试是否可以正常访问数据库")
    @GetMapping("/hello")
    public AjaxResult hello(HttpSession session) {
        return AjaxResult.success(port + ":" + session.getId() + ":hello world " + usersDao.queryById(1201581319114785L).getNickname());
    }
}
